<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="../underscore.js"></script>
  </head>
  <body>
    <ul id="name_list"></ul>

    <!-- 模板引擎 -->
    <script id="user-tmpl" type="text/html">
      <% for(let i=0;i<users.length;i++){%>
        <li>
          <% users[i].name %>
        </li>
      <%}%>
    </script>

    <script>
      let Ul = document.getElementById('name_list')

      let data = {
        users: [{ name: 'Lionel' }, { name: 'Alex' }, { name: 'John' }]
      }

      let precompile = _.template(
        document.getElementById('user-tmpl').innerHTML
      )

      Ul.innerHTML = precompile(data)
    </script>
  </body>
</html>
